<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<p>name= check1</p>
		<input type="checkbox" name="check1" id="">上网<br />
		 <input type="checkbox" name="check1" id="">买菜<br />
		 <input type="checkbox" name="check1" id="">旅游<br />
		 <input type="checkbox" name="check1" id="">电影<br />
		 <input type="checkbox" name="check1" id="">唱歌<br />
		 <input type="checkbox" name="check1" id="">阅读<br />
		
		 <p>name= check2</p>
		 <input type="checkbox" name="check2" id="">上网<br />
		 <input type="checkbox" name="check2" id="">买菜<br />
		 <input type="checkbox" name="check2" id="">旅游<br />
		 <input type="checkbox" name="check2" id="">电影<br />
		 <input type="checkbox" name="check2" id="">唱歌<br />
		 <input type="checkbox" name="check2" id="">阅读<br />
	</body>
	<script type="text/javascript">
	function autoCheck(name,limit){
	   var cks = document.getElementsByName(name);
	    function check() {
	        var checkedNum = 0;
	        for (var i = 0,len = cks.length; i < len ;i++) {
	            if(cks[i].checked) checkedNum++;
	            if(checkedNum > limit) {
	                return false;
	            }    
	        }
	        return true;
	   }
	    for (var i = 0,len = cks.length; i < len ;i++) {
	        cks[i].onclick = function (){
	            if(!check()){  
	                alert("最多选择"+limit+"个");  
	                this.checked = false;  
	            }  
	        }
	    } 
	};
	autoCheck("check1",3);
	autoCheck("check2",3);
	</script>
</html>
